make pydantic optional - #6786
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
Greptile SummaryThis PR makes pydantic an optional dependency of both
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| packages/reflex-base/src/reflex_base/event/processor/base_state_processor.py | Moves the pydantic find_spec check from per-event to module-import time, setting BaseModelV2 = None when pydantic is absent; hot-path guard is correct and well-commented. |
| packages/reflex-base/pyproject.toml | Moves pydantic from hard dependency to [project.optional-dependencies]; version constraint preserved. |
| pyproject.toml | Adds pydantic = ["reflex-base[pydantic]"] extra; db extra keeps pydantic as a direct dependency. |
| tests/units/test_optional_pydantic.py | New subprocess-based test that blocks pydantic via sys.meta_path filter + sys.modules purge, verifying core reflex functionality works without pydantic; well-structured isolation mechanism. |
| news/+pydantic-optional.breaking.md | Breaking change note documenting the removal of pydantic as a hard dependency and the new reflex[pydantic] extra. |
| uv.lock | Lockfile updated to reflect pydantic becoming optional; also includes an aiohttp version downgrade from 3.14.3 to 3.14.1. |
Reviews (8): Last reviewed commit: "Resolve pydantic presence once instead o..." | Re-trigger Greptile
masenf
left a comment
There was a problem hiding this comment.
interesting; i thought we had pydantic as optional for some time now, but i guess not...
I remember reading some git commits or changelogs which mentioned this as well - however somehow it currently isn't optional. I guess this is ready for review now. |
With pydantic optional, find_spec("pydantic") in _transform_event_arg
does a full sys.path scan on every dict-payload argument when pydantic
is absent (measured 85us per call; 0.64us after hoisting). Bind the
BaseModel reference once at import, like the other guarded sites.
|
Validated this end to end in a real app: installed the branch's packages into a clean venv (confirmed nothing pulls pydantic transitively — 40 packages, no pydantic), ran a counter app, and exercised state events in the browser — compile, hydration, and event round-trips all work without pydantic. Also confirmed the One perf issue surfaced and is fixed in 02f7152: |
No description provided.